<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue组件</title>
    <script src="https://unpkg.com/vue@next"></script>
    <!-- 
        1.像修改父组件中的数字,需要告诉一下父组件
        2.触发事件的时候用驼峰,监听事件的时候用"-"
     -->
</head>
<body>
    <div id="root"></div>
    <script>
        // vue的生命周期函数
        const app = Vue.createApp({
            data() {
                return {
                    count: 1
                }
            },
            methods: {
                btnAdd(param){
                    this.count+=param
                }
            },
            template: `
                <div>
                    <counter @add-one="btnAdd" :count="count" />
                </div>
            `
        });
        app.component('counter',{
            props: ['count'],
            // 向外部触发一个事件
            methods: {
                handleAddone() {
                    this.$emit('addOne',2)
                }
            },
            template: `
                <div @click="handleAddone">{{count}}</div>
            `
        })
        const vm = app.mount('#root');
    </script>
</body>
</html>